<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="livcos.org/ns/doc"
  exclude-result-prefixes="doc">
  
  <xsl:param name="item"/>
  <xsl:param name="label"/>
  <xsl:param name="uri"/>
  
  <xsl:template match="/">
    <xsl:variable name="obj" select="document($uri)/*"/>
    <item id="{{new-id()}}" xmlns="livcos.org/ns/map">
      <label>
        <xsl:value-of select="$label"/>
        <xsl:if test="normalize-space($label) = ''">
          <xsl:value-of select="$obj/@name"/>
        </xsl:if>
      </label>
      <doc:link id="{{new-id()}}" ref="{$uri}">
        <xsl:value-of select="$obj/@name"/>
      </doc:link>
      <doc:import id="{{new-id()}}" ref="{$uri}#{$obj/doc:paragraph[1]/@id}"/>
      <rels id="{{new-id()}}" group="main">
        <rel id="{{new-id()}}" ref="#{$item}"/>
      </rels>
    </item>
  </xsl:template>
  
</xsl:stylesheet>
